<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="../node_modules/bootstrap/dist/css/bootstrap.css">
    <title>Document</title>
    <style>
        .form-group {
            margin: 40px;
        }
        
        .form-control {
            margin: 10px;
        }
        
        .btn-default {
            border: 1px solid #ccc;
            margin-top: 40px;
        }
        
        .booo {
            border: 1px solid #e1e1f1;
            margin-top: 10px;
        }
    </style>
</head>

<body>
    <div class="container booo">
        <form class="form-inline">
            <div class="form-group">
                <label for="exampleInputName2">Name</label>
                <input type="text" class="form-control username" id="exampleInputName2" placeholder="Username">
            </div>
            <div class="form-group">
                <label for="exampleInputEmail2">Password</label>
                <input type="password" class="form-control password" id="exampleInputEmail2" placeholder="Password">
            </div>
            <button type="button" class="btn btn-default">添加</button>
        </form>
    </div>
</body>
<script src="../node_modules/jquery/dist/jquery.js"></script>
<script>
    $(() => {
        $(".btn-default").click(function() {
            if ($.trim($(".username").val()) && $.trim($(".password").val())) {
                $.ajax({
                    type: "post",
                    url: "/user/reg",
                    data: {
                        username: $.trim($(".username").val()),
                        password: $.trim($(".password").val()),
                        email: null
                    },
                    dataType: "json",
                    success: response => {
                        alert("添加成功")
                    }
                });
            } else {
                alert("请输入内容")
            }
        })
    })
</script>

</html>